﻿using MvvmFx.Common.ViewModels;

namespace MvvmFx.Samples.HowTos
{
    /// <summary>
    /// Singleton class to control the module and expose 
    /// it's state values, settings, and commands
    /// </summary>
    public class ApplicationViewModel : ViewModelBase
    {
        #region Instance Variables

        private ViewModelCollection _howTos;
        private ViewModelBase _selectedHowTo;

        #endregion

        #region Singleton Constructor

        private static readonly ApplicationViewModel _instance
            = new ApplicationViewModel();

        static ApplicationViewModel()
        {

        }

        /// <summary>
        /// Singleton Constructor 
        /// </summary>
        protected ApplicationViewModel()
        {
            _howTos = new ViewModelCollection();
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets the value of the <see cref=”_instance”/> property.
        /// </summary>
        public static ApplicationViewModel Instance
        {
            get { return _instance; }
        }

        /// <summary>
        /// Gets the value of the <see cref=”HowTos”/> property.
        /// </summary>
        public ViewModelCollection HowTos
        {
            get { return _howTos; }
        }

        /// <summary>
        /// Gets or sets the value of the <see cref=”SelectedHowTo”/> property.
        /// </summary>
        public ViewModelBase SelectedHowTo
        {
            get { return _selectedHowTo; }
            set
            {
                if (_selectedHowTo != value)
                {
                    _selectedHowTo = value;
                    OnPropertyChanged("SelectedHowTo");
                }
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Initialize the ApplicationViewModel
        /// </summary>
        public void Init()
        {
            // Build the collection of available How To.. examples
            //
            HowTosBuilder.Build();
        }

        #endregion
    }
}